package com.douqu.game.rmi;

import com.douqu.game.core.util.LogUtils;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-08-08 13:44
 */
public class RMIClient {

    public void start()
    {
        try {
            //在RMI服务注册表中查找名称为X的对象，并调用其上的方法

            String url = "rmi://192.168.2.228:1234/Test";
            LogUtils.info("连接RMI:" + url);

            IRMI rmi = (IRMI) Naming.lookup(url);

            LogUtils.info("RMI 链接成功: " + url);

            String result = rmi.test();

            LogUtils.info("返回结果 -> " + result);

            LogUtils.info("----------------");
        } catch (NotBoundException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new RMIClient().start();
    }
}
